package projectpractice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

public class Application {
    private static DishesPracticeService dishesPracticeService = new DishPracticeServiceImpl();

    public static void main(String[] args) {

        dishesPracticeService.init();
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String command = null;
            try {
                command = bufferedReader.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            System.out.println("执行命令" + command);
            if (command.startsWith("add ")) {
                String content = command.replaceAll("add ", "");
                initDishesPractice(content.split(" "));
            }
            if (command.startsWith("search ")) {
                String content = command.replaceAll("search ", "");
                search(content);
            }
        }
    }

    private static void search(String name) {
        DishesPracticeParam param = new DishesPracticeParam();
        param.setName(name);
        List<Dishes> dishesPracticeList = dishesPracticeService.search(param);
        for (Dishes dishesPractice : dishesPracticeList) {
            System.out.println("菜品名称:" + dishesPractice.getName());
            System.out.println("菜品价格:" + dishesPractice.getPrice());
            System.out.println("-------------------------");
        }
    }

    private static void initDishesPractice(String[] items) {
        Dishes dishesPractice = new Dishes();
        dishesPractice.setId(items[0]);
        dishesPractice.setName(items[1]);
        dishesPractice.setPrice(Double.valueOf(items[2]));
        dishesPracticeService.add(dishesPractice);
    }


}

